﻿using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;

namespace Gmantis.Controls.Chart
{
    public class LegendItemCollection : ReadOnlyCollection<LegendItem>, INotifyPropertyChanged, INotifyCollectionChanged
    {
        // Events
        public event NotifyCollectionChangedEventHandler CollectionChanged;
        protected event PropertyChangedEventHandler PropertyChanged;
        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        {
            add
            {
                this.PropertyChanged += value;
            }
            remove
            {
                this.PropertyChanged -= value;
            }
        }

        // Methods
        internal LegendItemCollection(System.Collections.ObjectModel.ObservableCollection<LegendItem> items)
            : base(items)
        {
            items.CollectionChanged += new NotifyCollectionChangedEventHandler(this.items_CollectionChanged);
            ((INotifyPropertyChanged)items).PropertyChanged += new PropertyChangedEventHandler(this.LegendItemCollection_PropertyChanged);
        }

        private void items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (this.CollectionChanged != null)
            {
                this.CollectionChanged(this, e);
            }
        }

        private void LegendItemCollection_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, e);
            }
        }
    }
}
